//
//  ExampleCollectionViewCell.m
//  MarianasTrench
//
//  Created by 付建国 on 16/3/18.
//  Copyright © 2016年 王爵. All rights reserved.
//

#import "ExampleCollectionViewCell.h"
#import "ExampleModel.h"

@interface ExampleCollectionViewCell ()

@property (nonatomic, strong) UIImageView *imageV;
@property (nonatomic, strong) UILabel *titleL;
@property (nonatomic, strong) UILabel *firstL;
@property (nonatomic, strong) UILabel *secondL;

@end

@implementation ExampleCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}
- (void)createSubView{
    self.imageV = [[UIImageView alloc] init];
    [self.contentView addSubview:_imageV];
    
    self.titleL = [[UILabel alloc] init];
    [self.contentView addSubview:_titleL];
    
    self.firstL = [[UILabel alloc] init];
    [self.contentView addSubview:_firstL];
    
    self.secondL = [[UILabel alloc] init];
    [self.contentView addSubview:_secondL];
}
- (void)setModel:(ListModel *)model{
    _model = model;
    [self fuzhi];
}
- (void)fuzhi{
//    [self.imageV sd_setImageWithURL:[NSURL URLWithString:_model.coverPath]];
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [self.imageV HANDLEIMAGE(_model.coverPath)];
    });
    
    self.titleL.text = _model.title;
    self.titleL.font = [UIFont systemFontOfSize:15];
    
    ExampleModel *firstModel = _model.firstKResults[0];
    NSString *firstStr = [NSString stringWithFormat:@"1 %@", firstModel.title];
    self.firstL.text = firstStr;
    self.firstL.font = [UIFont systemFontOfSize:12];
    self.firstL.textColor = [UIColor grayColor];
    
    ExampleModel *secondModel = _model.firstKResults[1];
    NSString *secondStr = [NSString stringWithFormat:@"2 %@", secondModel.title];
    self.secondL.text = secondStr;
    self.secondL.font = [UIFont systemFontOfSize:12];
    self.secondL.textColor = [UIColor grayColor];
    
}
// 布局
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    [super applyLayoutAttributes:layoutAttributes];
    self.imageV.frame = CGRectMake(0, 0, layoutAttributes.frame.size.height - 5, layoutAttributes.frame.size.height - 5);
    
    self.titleL.frame = CGRectMake(layoutAttributes.frame.size.height, 0, layoutAttributes.frame.size.width - layoutAttributes.frame.size.height - 5, 20);
    
    self.firstL.frame = CGRectMake(layoutAttributes.frame.size.height, 25, layoutAttributes.frame.size.width - layoutAttributes.frame.size.height - 5, 20);
    
    self.secondL.frame = CGRectMake(layoutAttributes.frame.size.height, layoutAttributes.frame.size.height - 20, layoutAttributes.frame.size.width - layoutAttributes.frame.size.height - 5, 20);
}

@end
